package com.example.mypetstore_back_management.Controller;

import com.example.mypetstore_back_management.domain.Account;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController{

    @ResponseBody
    @GetMapping("/findAllUserInfo")
    public ArrayList<Account> findAllUserInfo(Model model){
        System.out.println("发送表的信息");
        ArrayList<Account> accountArrayList = new ArrayList<>();
        for (int i=0;i<5;i++)
        {
            Account account = new Account();
            account.setUserid(String.valueOf(i));
            account.setPassword(String.valueOf(i));
            account.setTelephone(String.valueOf(i));
            account.setEmail(String.valueOf(i));
            account.setAddr1(String.valueOf(i));
            account.setAddr2(String.valueOf(i));
            account.setCity(String.valueOf(i));
            if(i==1||i == 3)
                account.setStatus(1);
            else account.setStatus(0);
            accountArrayList.add(account);
        }
        return accountArrayList;
    }

    @GetMapping("/login")
    public String login(){return "main";}

    @GetMapping("/delete")
    @ResponseBody
    public void delete(Account account){//account 存储了 删除行发来的 对象
        System.out.println("进入删除");
        System.out.println(account.getUserid()+" "+account.getTelephone()+" "+account.getCity());
        //JDBC操作
    }
    @GetMapping("/reset")
    @ResponseBody
    public void reset(Account account){//account 存储了 删除行发来的 对象
        System.out.println("进入重置");
        System.out.println(account.getUserid()+" "+account.getTelephone()+" "+account.getCity());
        System.out.println(account.getPassword());
        //JDBC操作
    }

    @GetMapping("/status")
    @ResponseBody
    public void status(String userid,int status){//account 存储了 删除行发来的 对象
        System.out.println("账号状态");
        System.out.println("账号："+userid);
        if(status == 0)
            System.out.println("账号禁用");
        else System.out.println("账号正常");
        //JDBC操作
    }

    @GetMapping("/edit")
    @ResponseBody
    public void edit(int userid,String telephone,String email,String addr1,String addr2,String city){//account 存储了 删除行发来的 对象
        System.out.println("进入编辑");
        System.out.println(userid);
        System.out.println(addr1);
        System.out.println(addr2);
        System.out.println(city);
        System.out.println(telephone);
        System.out.println(email);
        //JDBC操作
    }

    @GetMapping("/delAll")
    @ResponseBody
    public void delAll(String userIds){//account 存储了 删除行发来的 对象
        System.out.println("进入批量删除");
        System.out.println(userIds);
        String[] userId = userIds.split("/");
        for(int i = 0;i<userId.length;i++)
        {
            System.out.println(userId[i]);
        }
        //JDBC操作
    }
}
